<template>
<div class="app-container">
  <el-form :inline="true" :model="formInline" class="demo-form-inline">
  <el-form-item label="用户名">
    <el-input size="small" v-model="formInline.user" placeholder="用户名"></el-input>
  </el-form-item>
  <el-form-item label="手机号">
    <el-input size="small" v-model="formInline.phone" placeholder="手机号"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button size="small" type="primary" @click="onSubmit">查询</el-button>
  </el-form-item>
</el-form>
  <el-table ref="multipleTable" v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row empty-text="暂无数据">
    <el-table-column align="center" label="用户名" width="150">
      <template slot-scope="scope">
        {{ scope.row.name }}
      </template>
    </el-table-column>
    <el-table-column label="手机号">
      <template slot-scope="scope">
        {{ scope.row.phone }}
      </template>
    </el-table-column>
    <el-table-column label="积分" width="110" align="center">
      <template slot-scope="scope">
        <span>{{ scope.row.integral }}</span>
      </template>
    </el-table-column>
    <el-table-column label="注册时间" width="110" align="center">
      <template slot-scope="scope">
        {{ scope.row.date }}
      </template>
    </el-table-column>
    <el-table-column label="上次登录时间" width="180" align="center">
      <template slot-scope="scope">
        {{scope.row.dataLogin}}
      </template>
    </el-table-column>
    <el-table-column label="登录次数" width="180" align="center">
      <template slot-scope="scope">
        {{scope.row.loginNum}}
      </template>
    </el-table-column>
    <el-table-column label="状态" width="100" align="center">
      <template slot-scope="scope">
        <el-tag size="small" v-if="scope.row.state == 0" type="success">正常</el-tag>
        <el-tag size="small" v-else type="danger">封禁</el-tag>
      </template>
    </el-table-column>
    <el-table-column fixed="right" align="center" label="操作" width="100">
      <template slot-scope="scope">
        <el-button @click="edit(scope.row)" type="text">编辑</el-button>
        <el-button type="text" style="color:#ff0000;">{{scope.row.state == 0?'封禁':'解封'}}</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div style="margin:10px 0 0 0;text-align:right;">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 30, 50, 100]"
      :page-size="1"
      layout="total, sizes, prev, pager, next, jumper"
      :total="10">
    </el-pagination>
  </div>
</div>
</template>

<script>
import {
  getList
} from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [{
          name: 'test',
          phone: '13322221111',
          date: '2021-02-03',
          dataLogin: '2021-02-03 22:22:22',
          loginNum: 10,
          integral: 300,
          state: 0,
        },
        {
            name: 'test22',
            phone: '13322221111',
            date: '2021-02-03',
            dataLogin: '2021-02-03 22:22:22',
            loginNum: 10,
            integral: 300,
            state: 1,
          },
      ],
      listLoading: true,
      currentPage: 1,
      formInline: {
        user: '',
        region: ''
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    onSubmit() {

    },
    edit(row) {
      console.log(row)
      this.$router.push({
        path: '/users/edit'
      })
    },
    fetchData() {
      this.listLoading = true
      getList().then(response => {
        // this.list = response.data.items
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
}
</script>
